<?php

function member_list($gametype)
{
    global $disk;
    global $acl;
    global $curruser;
    global $conf;
    global $g_gametype_3d;
    global $g_init_mode_6h;
    global $g_init_mode_3d;
    $timeCheck = systime() - 2592000;
    $enabled = getvar("enabled");
    if ($enabled == "")
    {
        $enabled = 1;
    }
    $gameinit_name = array (0 => "关闭", 1 => "全部", 2 => "六合", 3 => "快开彩");
    $qctmp = "enabled>0";
    if ($enabled == 0)
    {
        $qctmp = "enabled=0";
    }
    $k_user = new k_users();
    echo $k_user->top_bar($gametype, "大股东管理" . ( $enabled == 0 ? "停用" : "启用" ), $GLOBALS['funlist']);
    if (!$enabled)
    {
        $sql = "SELECT * FROM `k_user` A where acl=" . $acl . " and A.enabled=0 order by account";
    }
    else
    {
        $sql = "SELECT * FROM `k_user` A where acl=" . $acl . " and A.enabled>0 order by account";
    }
    $rs = getdb($sql);
    if ($rs->eof)
    {
        echo "<font color=red>没有大股东！</font>";
    }
    else
    {
        echo "<table width=80% border=\"1\" cellspacing=\"1\" cellpadding=\"0\" class=\"mytable\">";
        echo "<tr class='td0 bgClc_{$gametype}' nowrap align=center>\r\n\t\t<td nowrap>大股东帐号</td>\r\n\t\t<td nowrap>名称</td>";
        echo "<td nowrap>彩类</td>";
        echo "<td nowrap>信用额度</td><td nowrap>公司占成</td><td nowrap>走飞</td><td nowrap>操盘</td>";
        echo "<td nowrap>新增/更新</td>" . ( "<td nowrap>最後登入</td>" ) . "<td nowrap>下层</td>" . "<td nowrap>权限</td>" . "<td nowrap>归属</td>" . "<td nowrap>建档</td>" . "<td nowrap>功能设定</td>" . "</tr>";
        while (!$rs->eof)
        {
			$parent=getdb("select gametype, mpercent,snow_open,protmod from  k_user_percent where user_id = ".$rs->f['id']." and  gametype in (0,12) order by gametype");
			$mpercent6h=$mpercent3s3=0;
			while(!$parent->eof){
				if($parent->f['gametype']==0)
				{
					$snow_open=$parent->f['snow_open'];
					$protmod=$parent->f['protmod'];
					$mpercent6h=$parent->f['mpercent'];
				}
				else
					$mpercent3s3=$parent->f['mpercent'];
				$parent->next();
			}
            echo "<tr class=td2 onmouseover=msover() onmouseout=msout()>";
            if ($timeCheck < $rs->f['createdt'])
            {
                $tempClass = " class=\"td4\" ";
            }
            else
            {
                $tempClass = "";
            }
            echo "<td nowrap {$tempClass}><a href='?op=subsidary&fp=shareowner&gametype={$gametype}&cmd=list&enabled=1&prev_id=" . $rs->f['id'] . "'>" . $rs->f['account'] . "</a>";
            echo "<td nowrap>" . $rs->f['name'];
            echo "<td nowrap>" . $gameinit_name[$rs->f['init_start_mode']];
            if (0 < $gametype)
            {
                /*$amoun_x = "";
                switch ($g_gametype_3d[$gametype]['type'])
                {
                    case 1 :
                        $amoun_x = "amount_3d";
                        break;
                    default :
                        $amoun_x = "amount_3s1";
                        break;
                }*/
                echo "<td align=right nowrap>" . n_to_c($rs->f["amoun"]);
                echo "<td nowrap align=right>(6h)" . ( 100 - $mpercent6h ) . "% / <font color=#0000ff>(快)" . ( 100 - $mpercent3s3 ) . "%</font></td>";
                if ($protmod == 1)
                {
                    echo "<td nowrap align=center>启用</td>";
                }
                else
                {
                    echo "<td nowrap align=center><font color=red>停用</font></td>";
                }
                if ($snow_open == 1)
                {
                    echo "<td nowrap align=center>启用</td></td>";
                }
                else
                {
                    echo "<td nowrap align=center><font color=red>停用</font></td>";
                }
            }
            else
            {
                echo "<td nowrap align=right>" . n_to_c($rs->f['amount'])."</td>";
                /*echo "<td nowrap align=right>" . $rs->f['rate0'];
                if ($rs->f['reat0_open'] == 1)
                {
                    echo "<td nowrap align=center>启用";
                }
                else
                {
                    echo "<td nowrap align=center><font color=red>停用</font>";
                }*/
                echo "<td nowrap align=right>(6h)" . ( 100 - $mpercent6h ) . "% / <font color=#0000ff>(快)" . ( 100 - $mpercent3s3 ) . "%</font></td>";
				if ($protmod == 1)
                {
                    echo "<td nowrap align=center>启用</td>";
                }
                else
                {
                    echo "<td nowrap align=center><font color=red>停用</font></td>";
                }
                if ($snow_open == 1)
                {
                    echo "<td nowrap align=center>启用</td>";
                }
                else
                {
                    echo "<td nowrap align=center><font color=red>停用</font></td>";
                }
            }
            echo "<td nowrap>" . ( $rs->f['updatedt'] == "" ? date("Y-m-d", $rs->f['createdt']) : date("Y-m-d", $rs->f['updatedt']) );
            echo "<td nowrap>" . ( $rs->f['lastlogdt'] == "" ? "" : date("Y-m-d", $rs->f['lastlogdt']) );
            $rs1 = getdb("select count(id) from k_user where enabled>0 and prev_id=" . $rs->f['id'] . " and " . $qctmp);
            echo "<td nowrap align=right>" . $rs1->f[0];
            if ($rs->f['enabled'] == 1)
            {
                echo "<td nowrap align=center>启用";
            }
            else if ($rs->f['enabled'] == 2)
            {
                echo "<td nowrap align=center bgcolor=red><font color=white>暂停</font>";
            }
            else
            {
                echo "<td nowrap align=center bgcolor=black><font color=white>停用</font>";
            }
            echo "<td nowrap>" . $rs->f['supe_account'];
            echo "<td nowrap>" . $rs->f['createAccount'];
            echo "<td nowrap><a href='?op=admin&fp=subsidary&gametype={$gametype}&cmd=edit&id=" . $rs->f['id'] . "'>修改</a> ";
            echo ":: <a href='?op=agent&fp=amount_3d&gametype={$gametype}&id=" . $rs->f['id'] . "'>限额</a>";
            echo "</td></tr>";
            $rs->next();
        }
        $rs->close();
        echo "</table>";
    }
}

function member_edit($gametype)
{
    global $acl;
    global $curruser;
    global $conf;
    global $g_init_mode_6h;
    global $g_init_mode_3d;
    global $g_menu_enabled;
    global $g_gametype_3d;
    $id = intval(getvar("id"));
    include_once( "class/class.disk.php" );
    $tpl = new Template2();
    $stbl = new Show_subsidary();
    $disk_chg = new disk();
    $reat0_open = $conf->get("reat0_open");
    $prev_id = 0;
    $u_prev_percent_Arr = getUserPercents($prev_id);
    $editpercentwod = $conf->get("edit_percent_wod");
    $superadmin = $curruser['account'] == G_SUPERACCOUNT && $curruser['acl'] == 255 ? 1 : 0;
    echo $stbl->top_bar($gametype, "大股东管理 " . ( 0 < $id ? "编辑" : "新增" ), $GLOBALS['funlist']);
    if (ispost())
    {
        include_once( "genagent/k_user_post.php" );
    }
    $tpl->load("main", "subsidary.htm");
    $tpl->set("action", "?" . $_SERVER['QUERY_STRING']);
    if (0 < $id)
    {
        $tpl->set("edit_disabled", "disabled");
        $rs = getdb("select * from k_user where acl=" . $acl . " and id=" . $id);
        $account = $rs->f['account'];
        if ($rs->eof)
        {
            diemsg("错误的大股东编号！");
        }
        if (!( date("w") == $editpercentwod || $editpercentwod == 7 || $superadmin ))
        {
            $tpl->set("chk_percent_day", "yes");
        }
        if (date("w") == $editpercentwod || $editpercentwod == 7 || $superadmin || date("Ymd", $rs->f['createdt']) == date("Ymd", systime()))
        {
            $readmode = "";
        }
        else
        {
            $readmode = " readonly";
        }
        $gamemod01 = "";
        $gamemod02 = "";
        $gamemod03 = "";
        switch ($rs->f['init_start_mode'])
        {
            case 1 :
                $gamemod01 = "checked";
                break;
            case 2 :
                $gamemod02 = "checked";
                break;
            case 3 :
                $gamemod03 = "checked";
                break;
        }
        if ($g_init_mode_6h && $g_init_mode_3d)
        {
            $list_gamemode = "<td class=td1>可用博彩类别</td>" . ( "<td class=td2 colspan=3>" ) . "<input type=radio name=gamemod value=1 {$gamemod01}> 全部" . "<input type=radio name=gamemod value=2 {$gamemod02}> 六合彩" . "<input type=radio name=gamemod value=3 {$gamemod03}> 快开彩" . "</td>";
            $tpl->set("radio_gamemode", $list_gamemode);
        }
        $tpl->set("passdesc", "<br><font color=#aaaaaa>有输入表示要更改使用者密码</font>");
        $tpl->set("noeditaccount", "disabled");
        $tpl->set("account", $rs->f['account']);
        $tpl->set("name", $rs->f['name']);
        $tpl->set("id", $id);
        $btnMymodifyStr = "<input type=button value=\"占成与信用额度异动记录\" onclick=\"javascript:showMymodifyPage({$gametype},'{$account}');\">";
        $tpl->set("deletebutton", "<input type=button value=编辑限额 onclick=editamount(" . $id . "," . $gametype . ")>{$btnMymodifyStr}");
        $tpl->set("enabled" . $rs->f['enabled'], "checked");
        $tpl->set("createdt", date("Y-m-d H:i:s", $rs->f['createdt']));
        if ($rs->f['updatedt'] != "")
        {
            $tpl->set("updatedt", date("Y-m-d H:i:s", $rs->f['updatedt']));
        }
        if ($rs->f['lastlogdt'] != "")
        {
            $tpl->set("lastlogdt", date("Y-m-d H:i:s", $rs->f['lastlogdt']));
            $tpl->set("lastlogip", $rs->f['lastlogip']);
        }
        $tpl->set("logcount", $rs->f['logcount']);
        $dk_browser = $disk_chg->Browser($id);
        $alldisk_3d = "";
        if ($dk_browser['disk1'] == 1)
        {
            $alldisk_3d .= "<input type=checkbox name=disk1mod checked> A 盘.&#12288;";
        }
        else
        {
            $alldisk_3d .= "<input type=checkbox name=disk1mod> A 盘.&#12288;";
        }
        if ($dk_browser['disk2'] == 1)
        {
            $alldisk_3d .= "<input type=checkbox name=disk2mod checked> B 盘.&#12288;";
        }
        else
        {
            $alldisk_3d .= "<input type=checkbox name=disk2mod> B 盘.&#12288;";
        }
        if ($dk_browser['disk3'] == 1)
        {
            $alldisk_3d .= "<input type=checkbox name=disk3mod checked> C 盘.&#12288;";
        }
        else
        {
            $alldisk_3d .= "<input type=checkbox name=disk3mod> C 盘.&#12288;";
        }
        if ($dk_browser['disk4'] == 1)
        {
            $alldisk_3d .= "<input type=checkbox name=disk4mod checked> D 盘.&#12288;";
        }
        else
        {
            $alldisk_3d .= "<input type=checkbox name=disk4mod> D 盘.&#12288;";
        }
        $tpl->set("alldisk_3d", $alldisk_3d);
        foreach ($g_gametype_3d as $gameid => $val)
        {
            if ($g_init_mode_6h && $gameid == 0 || $g_init_mode_3d && $gameid && $g_menu_enabled[$gameid])
            {
                $percent_rs = getdb("!!select * from k_user_percent Where user_id = {$id} and gametype={$gameid}");
                if ($percent_rs->eof)
                {
                    CreatePercents($id, $gameid);
                }
            }
            else
            {
                continue;
            }
            switch ($gameid)
            {
                case 0 :
                    $data_6h = array ("", $rs->f['amount']);
                    $tpl->set("amount", $stbl->amount_6h($data_6h));
                    $rate8mod01 = "";
                    $rate0mod00 = "";
                    $rate0mod01 = "";
                    if ($rs->f['reat0_open'] == 0)
                    {
                        $rate0mod00 = " checked";
                    }
                    else
                    {
                        $rate0mod01 = " checked";
                    }
                    $rate8mod01 = $rs->f['reat0_8_open'] == 1 ? " checked" : "";
                    if ($reat0_open)
                    {
                        $data_6h = array ($rs->f['rate0'], "1" . $rate0mod01, "0" . $rate0mod00, "rate8mod" . $rate8mod01);
                        $tpl->set("mreat", $stbl->reduce_6h($data_6h));
                    }
                    $percent_mod = $percent_rs->f['percent_sw'] == 1 ? " checked" : "";
                    $data_6h = array ("6h", "六合彩", intval($percent_rs->f['mpercent']) . $readmode, "percent_sw" . $percent_mod . $readmode, $u_prev_percent_Arr[0]['mpercent']);
                    $tpl->set("mpsen", $stbl->percent_6h($data_6h));
                    $snow_mod00 = "";
                    $snow_mod01 = "";
                    if ($percent_rs->f['snow_open'] == 0)
                    {
                        $snow_mod00 = " checked";
                    }
                    else
                    {
                        $snow_mod01 = " checked";
                    }
                    $data_6h = array ("paper6h", "六合彩操盘", "snow_mod", "1" . $snow_mod01, "0" . $snow_mod00);
                    $tpl->set("msnow", $stbl->protmod($data_6h));
                    $protmod00 = "";
                    $protmod01 = "";
                    if ($percent_rs->f['protmod'] == 0)
                    {
                        $protmod00 = " checked";
                    }
                    else
                    {
                        $protmod01 = " checked";
                    }
                    $data_6h = array ("paper6h", "六合彩走飞", "protmod", "1" . $protmod01, "0" . $protmod00);
                    $tpl->set("mprot", $stbl->protmod($data_6h));
                    break;
                default :
                    /*if ($g_gametype_3d[$gameid]['type'] == 1)
                    {
                        $data_3d = array ("3D彩共用", "3d", $rs->f['amount_3d']);
                        $tpl->set("amount_3d", $stbl->amount($data_3d));
                    }
                    else if (1 < $g_gametype_3d[$gameid]['type'])
                    {
                        $data_3s1 = array ("时时彩共用", "3s1", $rs->f['amount_3s1']);
                        $tpl->set("amount_3s1", $stbl->amount($data_3s1));
                    }*/
					if($gameid==12){
						$percent_mod = $percent_rs->f['percent_sw'] == 1 ? " checked" : "";
						$data_3d = array ($g_gametype_3d[$gameid]['en'], $g_gametype_3d[$gameid]['zc'], intval($percent_rs->f['mpercent']) . $readmode, "percent_sw_{$g_gametype_3d[$gameid]['en']}" . $percent_mod . $readmode, $u_prev_percent_Arr[$gameid]['mpercent']);
						$tpl->set("mpsen_{$g_gametype_3d[$gameid]['en']}", $stbl->percent($data_3d));
						$snow_mod_3d00 = "";
						$snow_mod_3d01 = "";
						if ($percent_rs->f['snow_open'] == 0)
						{
							$snow_mod_3d00 = " checked";
						}
						else
						{
							$snow_mod_3d01 = " checked";
						}
						$data_3d = array ("paper{$g_gametype_3d[$gameid]['en']}", "{$g_gametype_3d[$gameid]['zc']}操盘", "snow_mod_{$g_gametype_3d[$gameid]['en']}", "1" . $snow_mod_3d01, "0" . $snow_mod_3d00);
						$tpl->set("msnow_{$g_gametype_3d[$gameid]['en']}", $stbl->protmod($data_3d));
						$protmod_3d00 = "";
						$protmod_3d01 = "";
						if ($percent_rs->f['protmod'] == 0)
						{
							$protmod_3d00 = " checked";
						}
						else
						{
							$protmod_3d01 = " checked";
						}
						$data_3d = array ("paper{$g_gametype_3d[$gameid]['en']}", "{$g_gametype_3d[$gameid]['zc']}走飞", "protmod_{$g_gametype_3d[$gameid]['en']}", "1" . $protmod_3d01, "0" . $protmod_3d00);
						$tpl->set("mprot_{$g_gametype_3d[$gameid]['en']}", $stbl->protmod($data_3d));
					}
                    break;
            }
        }
        if ($curruser['acl'] == "255")
        {
            $disabled = "";
            if ($rs->f['disabled'] == 1)
            {
                $disabled = "<input type='checkbox' name='mbr_disabled' CHECKED=checked> 全线禁止登入";
            }
            else
            {
                $disabled = "<input type='checkbox' name='mbr_disabled'> 全线禁止登入";
            }
            $tpl->set("mbr_disabled_chk", $disabled);
        }
        $tpl->set("enabled0" . $rs->f['enabled'], "checked");
        //$tpl->set("sup_account", $rs->f['supe_account']);
    }
    else
    {
		$tpl->set("zctable","style='display:none'");
        if (G_ACCOUNT == 0)
        {
            $tpl->set("account", "s");
            $tpl->set("account_msg", "帐号必须为 s 开头,长度2~16 码.");
        }
        else
        {
            $tpl->set("account_msg", "帐号必须为6个以上的英文字母及数字混和组成, 长度勿超过16码.");
        }
        $alldisk_3d = "";
        $alldisk_3d .= "<input type=checkbox name=disk1mod checked> A 盘.&#12288;";
        $alldisk_3d .= "<input type=checkbox name=disk2mod checked> B 盘.&#12288;";
        $alldisk_3d .= "<input type=checkbox name=disk3mod checked> C 盘.&#12288;";
        $alldisk_3d .= "<input type=checkbox name=disk4mod checked> D 盘.&#12288;";
        $tpl->set("alldisk_3d", $alldisk_3d);
        $tpl->set("enabled01", "checked");
    }
    $tpl->set("submit", $id != "" ? "确定" : "新增" );
    $tpl->show("main");
}

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
if ($curruser['acl'] == 255 && $curruser['prev_id'] != 0 && !SubAccountRight($curruser, 2))
{
    exit();
}
if (isset($_SESSION['subaccount']) && $curruser['acl'] < 255)
{
    exit();
}
if ($curruser['enabled'] == 2)
{
    exit();
}
$gametype = intval(getvar("gametype"));
$chkGametype = chkGametype($gametype);
if ($chkGametype)
{
    include_once( "class_3d/CheckMode_3d.php" );
    $chk = new CheckMode_3d($curruser['acl'], 1, $gametype);
    $chk->checkShow3dPage();
    unset($chk);
    $ui = new UI_3D(true, "报表管理");
    $jslink = "<script language=\"JScript.Encode\" src=\"site.js\"></script>" . ( "<script language=\"VBScript.Encode\" src=\"site.vbs\"></script>" );
    $ui->set("jslink", $jslink);
    $ui->header();
}
else
{
    $ui = new UI(true, "报表管理");
}
if (isset($_SESSION['subaccount']) && $curruser['acl'] < 255)
{
    $ui->showErrorPage("你是子帐号，不能执行这个功能！");
    exit();
}
include_once( "class/class.acctMag.php" );
$conf = new Config();
$acl = 5;
switch (getvar("cmd"))
{
    case "add" :
        $funlist = " <a href=\"?op=admin&fp=subsidary&gametype={$gametype}&cmd=list&enabled=1\">启用列表</a>" . " <a href=\"?op=admin&fp=subsidary&gametype={$gametype}&cmd=list&enabled=0\">停用列表</a>";
        $funlist .= " &nbsp; <a href=\"javascript:history.back()\">回上一页</a>";
        member_edit($gametype);
        break;
    case "edit" :
        $id = intval(getvar("id"));
        $funlist = " <a href=\"?op=admin&fp=subsidary&gametype={$gametype}&cmd=list&enabled=1\">启用列表</a>" . " <a href=\"?op=admin&fp=subsidary&gametype={$gametype}&cmd=list&enabled=0\">停用列表</a>" . "<a href=\"?op=subsidary&fp=shareowner&gametype={$gametype}&cmd=add&prev_id={$id}\">新增下级</a>";
        $funlist .= " &nbsp; <a href=\"javascript:history.back()\">回上一页</a>";
        member_edit($gametype);
        break;
    default :
        $funlist = " <a href=\"?op=admin&fp=subsidary&gametype={$gametype}&cmd=list&enabled=1\">启用列表</a>" . " <a href=\"?op=admin&fp=subsidary&gametype={$gametype}&cmd=list&enabled=0\">停用列表</a>" . " <a href=\"?op=admin&fp=subsidary&gametype={$gametype}&cmd=add\">新增</a>";
        member_list($gametype);
        break;
}
echo "</table>";
$ui->footer();
?>